var e, t, a = require("../../@babel/runtime/helpers/interopRequireDefault"), n = a(require("../../@babel/runtime/regenerator")), i = a(require("../../@babel/runtime/helpers/asyncToGenerator")), r = require("../../1D8980678A52ABCF7BEFE860FD67FE64.js"), s = require("../../E52ED4948A52ABCF8348BC934D77FE64.js"), o = require("../../3F2EFC058A52ABCF59489402DCA7FE64.js"), u = getApp();

Page({
    data: {
        douyin: r.IMGPATH + "but_douyin.png",
        icons: {
            icon01: r.IMGPATH + "ic_luck.png",
            icon02: r.IMGPATH + "qinggan.png",
            icon03: r.IMGPATH + "quwei2.png",
            icon04: r.IMGPATH + "xingge.png",
            icon05: r.IMGPATH + "ic_hot.png",
            icon06: r.IMGPATH + "ic_recommended.png",
            icon07: r.IMGPATH + "ic_search_2.png"
        },
        bannerList: [],
        banner: {
            indicatorDots: !0,
            indicatorColor: "rgba(255, 255, 255, .56)",
            indicatorActiveColor: "rgba(255, 255, 255, 1)",
            autoplay: !0,
            interval: 5e3,
            circular: !0,
            vertical: !1,
            duration: 500
        },
        keyWord: "",
        pageNumber: 1,
        pageSize: 10,
        questionCategory: "",
        list: [],
        status: !1,
        topDistance: "",
        lineHeight: "",
        avticeTopStatus: !1,
        paddingHeight: 0,
        adShow: !1
    },
    onReady: function() {},
    onShow: function() {},
    closeCom: function() {
        this.setData({
            adShow: !1
        });
    },
    onLoad: function(e) {
        if (e.userId) try {
            wx.setStorageSync("userId", e.userId), this.setData({
                adShow: !0
            });
        } catch (e) {}
        if (e.isNewUser) try {
            wx.setStorageSync("isNewUser", e.isNewUser);
        } catch (e) {} else wx.setStorageSync("isNewUser", !1);
        wx.showLoading({
            title: "加载中",
            duration: 500
        });
        var t = u.globalData.headerBtnPosi, a = 2 * t.height + 36, n = 2 * t.top;
        this.setData({
            topDistance: n,
            lineHeight: a,
            paddingHeight: a + n
        }), this.getBanner(), this.fetchData();
    },
    fetchData: (t = (0, i.default)(n.default.mark(function e() {
        var t, a, i, r, u, c, d, g, p, l;
        return n.default.wrap(function(e) {
            for (;;) switch (e.prev = e.next) {
              case 0:
                return t = this.data, a = t.keyWord, i = t.pageNumber, r = t.pageSize, u = t.questionCategory, 
                c = t.list, d = t.status, e.next = 3, (0, s.ajax)({
                    url: "/api/testQuestion/getPager",
                    data: {
                        keyWord: a,
                        pageSize: r,
                        pageNumber: i,
                        questionCategory: u
                    }
                });

              case 3:
                if ((g = e.sent).code) {
                    e.next = 14;
                    break;
                }
                if ((p = g.data.data).length) {
                    e.next = 8;
                    break;
                }
                return e.abrupt("return");

              case 8:
                for (p.length >= r ? (i++, d = !0) : d = !1, l = 0; l < p.length; l++) p[l].reads = (0, 
                o.getRandomNumberByRange)(1e3, 1e5);
                c = c.concat(p), this.setData({
                    pageNumber: i,
                    list: c,
                    status: d
                }), e.next = 15;
                break;

              case 14:
                this.setData({
                    status: !1
                });

              case 15:
                return e.abrupt("return", d);

              case 16:
              case "end":
                return e.stop();
            }
        }, e, this);
    })), function() {
        return t.apply(this, arguments);
    }),
    bindscroll: function(e) {
        var t = this.data, a = t.topDistance, n = t.avticeTopStatus, i = e.detail.scrollTop;
        i > 2 * a && !n && this.setData({
            avticeTopStatus: !0
        }), i <= 2 * a && n && this.setData({
            avticeTopStatus: !1
        });
    },
    getBanner: (e = (0, i.default)(n.default.mark(function e() {
        var t, a, i;
        return n.default.wrap(function(e) {
            for (;;) switch (e.prev = e.next) {
              case 0:
                return e.next = 2, (0, s.ajax)({
                    url: "/api/testQuestion/getBannerList"
                });

              case 2:
                (t = e.sent).code || (a = t.data, i = [], a.forEach(function(e) {
                    e.openBanner && i.push(e);
                }), this.setData({
                    bannerList: i
                }), wx.hideLoading());

              case 4:
              case "end":
                return e.stop();
            }
        }, e, this);
    })), function() {
        return e.apply(this, arguments);
    }),
    lowerScroll: function() {
        this.data.status && this.fetchData();
    },
    jumpDetail: function(e) {
        var t = e.currentTarget.dataset.id;
        if (!t) throw new Error("detail id 缺失");
        wx.navigateTo({
            url: "/pages/detail/index?id=" + t
        });
    },
    jumpList: function(e) {
        var t = e.currentTarget.dataset.cate;
        if (!t) throw new Error("分类 id 缺失");
        wx.navigateTo({
            url: "/pages/list/index?cate=" + encodeURIComponent(t)
        });
    },
    jumpSearch: function() {
        wx.navigateTo({
            url: "/pages/search/index"
        });
    },
    onShareAppMessage: function(e) {
        return {
            title: "趣测研究所",
            imageUrl: item.coverImgUrl,
            path: "/pages/index/index"
        };
    }
});